package com.lh0811.forge.pserv.basic.server.adapter.controller;

import com.github.pagehelper.PageInfo;
import com.lh0811.forge.dependency.basic_web.constant.AuthConstant;
import com.lh0811.forge.dependency.basic_web.response.ServerResponse;
import com.lh0811.forge.pserv.basic.server.repository.entity.CommConfig;
import com.lh0811.forge.pserv.basic.server.repository.entity.CommConfigType;
import com.lh0811.forge.pserv.basic.server.service.CommConfigService;
import com.lh0811.forge.pserv.basic.api.param.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "基础服务-配置管理")
@RestController
@RequestMapping("/forge/plate/v1/basic/config")
public class ConfigController {

    @Resource
    private CommConfigService commConfigService;

    @GetMapping("/type/query/page")
    @Operation(summary = "配置类型查询(分页)", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<PageInfo<CommConfigType>> configTypeQueryPage(@ParameterObject CommConfigTypeQueryPageParam param) throws Exception {
        return ServerResponse.createBySuccess(commConfigService.configTypeQueryPage(param));
    }

    @GetMapping("/type/query/list")
    @Operation(summary = "配置类型查询(不分页)", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<List<CommConfigType>> configTypeQueryList(@ParameterObject CommConfigTypeQueryListParam param) throws Exception {
        return ServerResponse.createBySuccess(commConfigService.configTypeQueryList(param));
    }


    /**
     * 配置类型创建
     */
    @PutMapping("/type/create")
    @Operation(summary = "配置类型创建", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse configTypeCreate(@RequestBody CommConfigTypeCreateParam param) throws Exception {
        commConfigService.configTypeCreate(param);
        return ServerResponse.createBySuccess();
    }

    /**
     * 配置类型更新
     */
    @PostMapping("/type/update")
    @Operation(summary = "配置类型更新", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse configTypeUpdate(@RequestBody CommConfigTypeUpdateParam param) throws Exception {
        commConfigService.configTypeUpdate(param);
        return ServerResponse.createBySuccess();
    }

    /**
     * 配置类型删除
     */
    @DeleteMapping("/type/delete/{confTypeId}")
    @Operation(summary = "配置类型删除", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse configTypeDelete(@PathVariable(value = "confTypeId") Long confTypeId) throws Exception {
        commConfigService.configTypeDelete(confTypeId);
        return ServerResponse.createBySuccess();
    }


    /**
     * 配置创建
     */
    @PutMapping("/create")
    @Operation(summary = "配置创建", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse configCreate(@RequestBody CommConfigCreateParam param) throws Exception {
        commConfigService.configCreate(param);
        return ServerResponse.createBySuccess();
    }

    @DeleteMapping("/delete/{configId}")
    @Operation(summary = "配置创建", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse configDelete(@PathVariable(value = "configId") Long configId) throws Exception {
        commConfigService.configDelete(configId);
        return ServerResponse.createBySuccess();
    }

    /**
     * 配置更新
     */
    @PostMapping("/update")
    @Operation(summary = "配置更新", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse configUpdate(@RequestBody CommConfigUpdateParam param) throws Exception {
        commConfigService.configUpdate(param);
        return ServerResponse.createBySuccess();
    }

    @GetMapping("/query/page")
    @Operation(summary = "配置列表查询(分页)", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<PageInfo<CommConfig>> configQueryPage(@ParameterObject CommConfigQueryPageParam param) throws Exception {
        return ServerResponse.createBySuccess(commConfigService.configQueryPage(param));
    }

    @GetMapping("/query/list")
    @Operation(summary = "配置列表查询(不分页)", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<List<CommConfig>> configQueryList(@ParameterObject CommConfigQueryListParam param) throws Exception {
        return ServerResponse.createBySuccess(commConfigService.configQueryList(param));
    }

}
